package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.OutDrugBean;
import com.project.bean.OutWareHouseBean;
import com.project.bean.UserBean;
import com.project.service.IWareHouseService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.time.LocalDate;
import java.util.Map;

/**
 * @author RJ
 * @date 2022/9/16 10:34
 */
@RestController
@RequestMapping("wareHouse")
public class WareHouseController {
    @Resource
    private IWareHouseService wareHouseService;

    @RequestMapping("add")
    public String addWareHouse(OutWareHouseBean outWareHouseBean, HttpServletRequest request) {
        HttpSession session = request.getSession();
        Map<Integer, OutDrugBean> map = (Map<Integer, OutDrugBean>) session.getAttribute("map");
        wareHouseService.addWareHouse(outWareHouseBean, map);
        map.clear();
        return "ok";
    }

    @RequestMapping("get")
    public OutWareHouseBean getOutInfo(Integer outId) {
        OutWareHouseBean outWareHouseBean = wareHouseService.getOutInfo(outId);
        return outWareHouseBean;
    }

    @RequestMapping("info")
    public IPage<OutWareHouseBean> cutOutByItem(Integer pageNo, Integer pageSize, LocalDate startDate, LocalDate endDate, String outUser) {
        IPage<OutWareHouseBean> page = wareHouseService.cutOutByItem(pageNo, pageSize, startDate, endDate, outUser);
        return page;
    }
}
